<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />
<div class="tabs-header">
                <el-tabs v-model="activeName" type="card" class="file-tabs" @tab-click="handleClick">
                    <el-tab-pane :label="label" :name="name" v-for="(label, name) in categoryList" :key="name"></el-tab-pane>
                </el-tabs>
				</div>
        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('Quick search placeholder', { fields: 'ID' })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table />

        <!-- 表单 -->
        <PopupForm  />
    </div>
</template>

<script setup lang="ts">
import { provide, ref } from 'vue'
import baTableClass from '/@/utils/baTable'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'
import type { TabsPaneContext } from 'element-plus'

defineOptions({
    name: 'routine/url',
})
const activeName = ref('')
const categoryList = ref({
    '': '全部',
	'base':'基础链接',
	'vip':'会员中心',
	'page':'页面链接',
})
const { t } = useI18n()
const baTable = new baTableClass(
    new baTableApi('app/url/'),
    {
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('Id'), prop: 'id', align: 'center', operator: '=', operatorPlaceholder: t('Id'), width: 70 },
            { 
				label: '类型', 
				prop: 'type', 
				align: 'center', 
				render:'tag', 
				operator: 'IN', 
				operatorPlaceholder: t('Fuzzy query'),
				custom: {base:'info', vip: 'success', page: 'danger'},
				replaceValue: {base:'基础链接', vip: '会员中心', page: '页面链接'},
			},
            { label: '名称', prop: 'name', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
            { label: '路径', prop: 'url', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
            { label: '排序', prop: 'weigh', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
            { label: t('Create time'), prop: 'createtime', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
            {
                label: t('Operate'),
                align: 'center',
                width: '150',
                render: 'buttons',
                buttons: defaultOptButtons(['weigh-sort', 'edit', 'delete']),
                operator: false,
            },
        ],
        dblClickNotEditColumn: [undefined],
    },
    {
        defaultItems: {
            type: 'base',
			weigh : 100
        },
    },
	{},
	{
		getEditData({ res }) {
			if(res && res.data) {
				 baTable.form.items = res.data
			}
		}
	}
)

// 点击分类标签切换查询条件
const handleClick = (tab: TabsPaneContext, event: Event) => {
    baTable.comSearch.form.type = tab.props.name
    baTable.onTableAction('com-search', {})
}
// 重写auth方法，绕过权限控制，始终返回true
baTable.auth = function () {
    return true
}
baTable.mount()
baTable.getData()

provide('baTable', baTable)
</script>

<style scoped lang="scss">
	.tabs-header {
	    display: flex;
	    justify-content: space-between;
	}
	
	.table-header-operate {
	    margin-left: 12px;
	}
	.table-header-operate-text {
	    margin-left: 6px;
	}
	
	.file-tabs :deep(.el-tabs__header) {
	    border-bottom: none;
	    margin-bottom: 0;
	}
	.file-tabs :deep(.is-active) {
	    background-color: #fff;
	}
	
</style>
